<template>
    <div class="goods-container">
        <router-link class="goods-item" v-for="item in goods" :key="item.id" :to="'/home/goodsinfo/'+item.id">
            <img :src="item.img_url" alt="">
            <div class="title">
                <h1>{{item.title}}</h1>
            </div>
            <p class="price">
                <span class="new">￥{{item.sell_price}}</span>
                <span class="old">￥{{item.market_price}}</span>
            </p>
            <p class="sale">
                <span>热卖中</span>
                <span>{{item.stock_quantity}}</span>
            </p>
        </router-link>
    </div>
</template>

<script>
export default {
    data(){
        return{
            pageIndex:1, //分页的页数
            goods:[]
        }
    },
    created(){
        this.getGoods()
    },
    methods:{
        getGoods(){
            this.$http.get("api/getgoods?pageindex="+this.pageIndex).then(result => {
                
                if(result.body.status===0){
                    this.goods=result.body.message
                }
            })
        }
    }
}
</script>

<style lang="scss" scoped>
.goods-container{
    padding:4px;
    display:flex;
    justify-content: space-between;
    flex-wrap: wrap;
    margin-bottom:70px;
    .goods-item{
        background-color: #eee;
        width:49%;
        border:1px solid #eee;
        box-shadow: 0 0 10px  #eee;
        margin-bottom: 4px;
        // 解决由于标题的大小，使得上下组件不对齐问题
        display: flex;
        flex-direction: column;      
        justify-content: space-between; 
        min-height: 308px;
        .title{
            h1{
                font-size:14px;
                line-height:20px;
            }
        }
        img{
            width:100%;
            min-height:170px;
        }
        .price{
            .old{
                font-size:12px;
                text-decoration: line-through;
                margin-left:10px;
            }
            .new{
                color:red;
                font-size:15px;
            }
        }
        .sale{
            display:flex;
            justify-content:space-between;
            margin:3px;
            font-size:14px;
        }
    }
}
</style>
